home *** CD-ROM | disk | FTP | other *** search
/ Amoszine 11 / Amoszine 11 (Disk 2 of 2).adf / Ben_Wyatt_Source.lha / Rotation.AMOS / Rotation.amosSourceCode
AMOS Source Code  |  2004-04-12  |  2KB  |  62 lines

  1. ' Rotation 
  2. ' ~~~~~~~~ 
  3. ' by Ben Wyatt, bwyatt@paston.co.uk
  4. '
  5. ' Rotates some graphics at any angle 
  6.  
  7. ' Needs it in degree mode - you can probably change it to radians if you're
  8. ' wierd, or to use AMCAFs Qsin and Qcos (also use Fplot/point or Turboplot/point)
  9. Degree 
  10.  
  11. Load Iff Fsel$("","","Select an IFF picture"),0
  12.  
  13. Screen Open 1,640,16,2,Hires : Curs Off : Screen To Back 
  14. Screen Display 1,128,37,320,16
  15. Screen 0 : Screen Display 0,128,37+9,Screen Width,Screen Height
  16.  
  17. Screen 1 : Centre "Select centre point"
  18. Screen 0 : Wait Vbl : Limit Mouse 
  19. Repeat 
  20.    XM=X Screen(X Mouse) : YM=Y Screen(Y Mouse) : MK=Mouse Key
  21. Until MK>0
  22.  
  23. Screen 0
  24. ' Grab each bit of the rotation (step of 5 degrees)
  25. STP=5
  26. For N=STP To 360 Step STP
  27.    _ROTATE[XM,YM,16,200,200,N]
  28.    Get Bob N/STP,200-16,200-16 To 200+16,200+16
  29.    No Mask N/STP
  30. Next N
  31.  
  32. ' Loop the animation 
  33. MK=False
  34. Repeat 
  35.    For N=STP To 360 Step STP
  36.       Paste Bob 100-16,100-16,N/STP
  37.       Wait Vbl 
  38.       MK=(Mouse Key>0) or MK
  39.    Next N
  40. Until MK
  41.  
  42. Procedure _ROTATE[XP,YP,R,XT,YT,ANG]
  43.    
  44.    ' Rotate area around centre point XP,YP to box with centre XT,YT and 
  45.    ' width/height R, at an angle ANG
  46.    
  47.    For X=XT-R To XT+R
  48.       For Y=YT-R To YT+R
  49.          ' Work out the distance from the centre point
  50.          DIST=Sqr((X-XT)*(X-XT)+(Y-YT)*(Y-YT))*256
  51.          If DIST>0
  52.             ' Work out the angle 
  53.             ANGT=Acos(((Y-YT)*256)/(DIST*1.0)) : If X-XT<0 : ANGT=360-ANGT : End If 
  54.          Else 
  55.             ANGT=0
  56.          End If 
  57.          ' Plot the pixel, of the colour of the source point :-?
  58.          Plot X,Y,Point(XP+(Sin(ANGT-ANG)*DIST)/256,YP+(Cos(ANGT-ANG)*DIST)/256)
  59.       Next Y
  60.    Next X
  61.    
  62. End Proc